package com.app.shop.controller.wx;

import com.app.shop.controller.system.BaseController;
import com.app.shop.entity.WgOrder;
import com.app.shop.entity.show.WxHomeShow;
import com.app.shop.entity.show.WxModel;
import com.app.shop.entity.show.WxOrderModel;
import com.app.shop.entity.show.WxProductOrderModel;
import com.app.shop.service.shop.WgOrderService;
import com.app.shop.util.ApiRest;
import com.app.shop.util.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;


/**
 * 订单模块
 *
 * @author chenliwei
 * @version v1.0 2017-11-5
 */
@Controller
@RequestMapping(value = "/api/order")
public class WxOrderController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(WxOrderController.class);

    @Autowired
    public WgOrderService orderService;


    /**
     * 创建订单
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/createOrder")
    public ApiRest createOrder(
            HttpServletRequest request, HttpServletResponse response,
            @RequestParam(value = "commodityId", required = true) Integer comId,
            @RequestParam(value = "phone", required = true) String phone,
            @RequestParam(value = "name", required = true) String name) throws Exception {
        //等待获取用户ID方法
        Integer userId =null;
        WgOrder wgOrder = orderService.insertOrderInfo( userId,  comId, phone,  name);

        return new ApiRest(Constant.REST_SUCCESS_CODE, Constant.SUCCESS_MESSAGE, null);
    }

    /**
     * 用户订单详情
     * @param proId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/orderList")
    public ApiRest getOrderList(Integer proId) {

        List<WxOrderModel> list= new ArrayList<WxOrderModel>();
        for(int j=1;j<10;j++) {
            WxOrderModel wxOrderModel = new WxOrderModel();
            wxOrderModel.setTime("2019-01-12 11:11:11");
            wxOrderModel.setOrderId("SFDFWWE12019111201");
            wxOrderModel.setState(1);
            wxOrderModel.setTotalPrice(123.5);
            wxOrderModel.setGoodsList(new ArrayList<>());
            WxProductOrderModel wxProductModel = new WxProductOrderModel();
            wxProductModel.setProId(1001);
            wxProductModel.setName("健身产品");
            wxProductModel.setShowStr("减肥健身,减肥健身,减肥健身");
            wxProductModel.setPrice(Double.valueOf(299));
            wxProductModel.setProImage("http://127.0.0.1:9999/static/image/banner1.jpg");
            wxProductModel.setMaxNum(5);
            wxProductModel.setPriceOld(Double.valueOf(699));
            wxProductModel.setNum(2);
            wxOrderModel.getGoodsList().add(wxProductModel);

            list.add(wxOrderModel);
        }
        for(int j=1;j<10;j++) {
            WxOrderModel wxOrderModel = new WxOrderModel();
            wxOrderModel.setTime("2019-01-12 11:11:11");
            wxOrderModel.setOrderId("SFDFWWE12019111201");
            wxOrderModel.setState(2);
            wxOrderModel.setTotalPrice(123.5);
            wxOrderModel.setGoodsList(new ArrayList<>());
            WxProductOrderModel wxProductModel = new WxProductOrderModel();
            wxProductModel.setProId(1001);
            wxProductModel.setName("健身产品");
            wxProductModel.setShowStr("减肥健身,减肥健身,减肥健身");
            wxProductModel.setPrice(Double.valueOf(299));
            wxProductModel.setProImage("http://127.0.0.1:9999/static/image/banner1.jpg");
            wxProductModel.setMaxNum(5);
            wxProductModel.setPriceOld(Double.valueOf(699));
            wxProductModel.setNum(2);

            wxOrderModel.getGoodsList().add(wxProductModel);

            list.add(wxOrderModel);
        }

        for(int j=1;j<10;j++) {
            WxOrderModel wxOrderModel = new WxOrderModel();
            wxOrderModel.setTime("2019-01-12 11:11:11");
            wxOrderModel.setOrderId("SFDFWWE12019111201");
            wxOrderModel.setState(3);
            wxOrderModel.setTotalPrice(123.5);
            wxOrderModel.setGoodsList(new ArrayList<>());
            WxProductOrderModel wxProductModel = new WxProductOrderModel();
            wxProductModel.setProId(1001);
            wxProductModel.setName("健身产品");
            wxProductModel.setShowStr("减肥健身,减肥健身,减肥健身");
            wxProductModel.setPrice(Double.valueOf(299));
            wxProductModel.setProImage("http://127.0.0.1:9999/static/image/banner1.jpg");
            wxProductModel.setMaxNum(5);
            wxProductModel.setPriceOld(Double.valueOf(699));
            wxProductModel.setNum(2);
            wxOrderModel.getGoodsList().add(wxProductModel);


            list.add(wxOrderModel);
        }
        return new ApiRest(Constant.REST_SUCCESS_CODE, Constant.SUCCESS_MESSAGE, list);
    }


}